package tools.keytools;

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;

public class RSAKeyPairGenerator {

    public static KeyPair generateKeyPair() throws Exception {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(1024); // 你可以选择1024, 2048, 4096等位长度
        return keyGen.generateKeyPair();
    }

    public static void main(String[] args) throws Exception {
        KeyPair keyPair = generateKeyPair();
        PublicKey publicKey = keyPair.getPublic();
        PrivateKey privateKey = keyPair.getPrivate();


     SecureRandom instance = new SecureRandom();
        System.out.println(instance.toString());

        // 这里可以将PublicKey和PrivateKey保存到文件或者数据库中
    }
}